package com.zretc.kscxmz.controller;

import com.github.pagehelper.PageInfo;
import com.zretc.kscxmz.entity.Dept;
import com.zretc.kscxmz.services.DeptService;
import com.zretc.kscxmz.services.impl.DeptServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/Dept")
public class DeptController {
    private static final Logger logger = LoggerFactory.getLogger(DeptController.class);

    @Autowired
    private DeptService deptService;

    @RequestMapping("/getCompanyByPage")
    public @ResponseBody
    PageInfo<Dept> getCompanyByPage(@RequestParam(value = "pageNum")String pageNum,
                                    @RequestParam(value = "pageSize")String pageSize
    ){
        logger.info("======查询部门列表======");
        logger.info("====pageNum:"    + pageNum);
        logger.info("====pagleSize:"   + pageSize);

        Map<String, String> map = new HashMap<>();
        map.put("pageNum",pageNum);
        map.put("pageSize",pageSize);
        //调用业务层
        PageInfo<Dept> companyByPage = deptService.getCompanyByPage(map);
        logger.info("====companyByPage:"   + companyByPage);
        return companyByPage;

    }

    @RequestMapping("/getCompanyById")
    public @ResponseBody
    Dept getCompanyById(@RequestParam(value = "deptId")Integer deptId){
        logger.info("=====通过部门ID查询部门信息======");
        logger.info("====deptId:"    + deptId);

        //调用业务层
        Dept companyByPage = deptService.getDeptInfoById(deptId);
        logger.info("====companyByPage:"   + companyByPage);
        return companyByPage;
    }

    @RequestMapping("/deleteDeptInfo")
    public @ResponseBody
    int deleteDeptInfo(@RequestParam(value = "deptId")String deptId){
        logger.info("=====通过部门ID删除部门信息======");
        logger.info("====Id:"    + deptId);

        //调用业务层
        int Id = Integer.parseInt(deptId);
        int companyByPage = deptService.deleteDeptInfo(Id);
        logger.info("====companyByPage:"   + companyByPage);
        return companyByPage;
    }



    @RequestMapping("/updateDeptInfo")
    public @ResponseBody
    int updateDeptInfo(@RequestParam(value = "deptName")String deptName,
                       @RequestParam(value = "deptTel")String deptTel,
                       @RequestParam(value = "email")String email,
                       @RequestParam(value = "deptAddr")String deptAddr,
                       @RequestParam(value = "deptId")Integer deptId){
        logger.info("=====通过部门ID修改部门信息======");
        logger.info("====deptName:"  + deptName);
        logger.info("====deptId:"    + deptId);
        logger.info("====email:"  + email);
        logger.info("====deptAddr:"    + deptAddr);
        logger.info("====deptName:"  + deptName);

        //调用业务层
        Map<String, Object> map = new HashMap<>();
        map.put("deptName",deptName);
        map.put("deptId",deptId);
        map.put("email",email);
        map.put("deptAddr",deptAddr);
        map.put("deptTel",deptTel);
        int companyByPage = deptService.updateDeptInfo(map);
        logger.info("====companyByPage:"   + companyByPage);
        return companyByPage;
    }

    @RequestMapping("/addDeptInfo")
    public @ResponseBody
    int addDeptInfo(@RequestParam(value = "deptName")String deptName,
                    @RequestParam(value = "deptTel")String deptTel,
                    @RequestParam(value = "email")String email,
                    @RequestParam(value = "deptAddr")String deptAddr,
                    @RequestParam(value = "deptId")Integer deptId){
        logger.info("======添加部门信息======");
        logger.info("====deptName:"  + deptName);
        logger.info("====deptId:"    + deptId);
        logger.info("====email:"  + email);
        logger.info("====deptAddr:"    + deptAddr);
        logger.info("====deptName:"  + deptName);

        //调用业务层
        Map<String, Object> map = new HashMap<>();
        map.put("deptName",deptName);
        map.put("deptId",deptId);
        map.put("email",email);
        map.put("deptAddr",deptAddr);
        map.put("deptTel",deptTel);
        int companyByPage = deptService.addDeptInfo(map);
        logger.info("====companyByPage:"   + companyByPage);
        return companyByPage;
    }





}
